package org.xqp.pay.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.xqp.basic.service.impl.BaseServiceImpl;
import org.xqp.basic.util.LoginContextUtil;
import org.xqp.pay.domain.PayBill;
import org.xqp.pay.service.IPayBillService;
import org.xqp.user.domain.Logininfo;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Service
@Transactional
public class PayBillServiceImpl extends BaseServiceImpl<PayBill> implements IPayBillService {

    @Override
    public void save(Long businessKey,
                     Integer businessType,
                     String title,
                     BigDecimal money,
                     Integer payChannel,
                     Long shopId,
                     String shopName,
                     String payNo) {

        PayBill bill = new PayBill();
        //业务KEY
        bill.setBusinessKey(businessKey);
        //业务类型
        bill.setBusinessType(businessType);
        bill.setCreateTime(new Date());
        bill.setDigest(title);
        bill.setMoney(money);
        //用户
        Logininfo loginContext = LoginContextUtil.getLoginContext();
        bill.setNickName(loginContext.getUsername());
        bill.setUser_id(loginContext.getId());
        //支付方式
        bill.setPayChannel(payChannel);
        //宠物店铺ID
        bill.setShop_id(shopId);
        bill.setShopName(shopName);
        //状态
        bill.setState(PayBill.SATET_WAIT_PAY);
        bill.setUnionPaySn(payNo);

        // 将支付单保存到数据库
        super.insert(bill);
    }
}
